/**
 * Copyright (c) 2013, FPX and/or its affiliates. All rights reserved.
 * Use, Copy is subject to authorized license.
 */
package com.fpx.open.platform.domain.track;

import java.util.ArrayList;
import java.util.List;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

/**
 * @author dranson
 * @date 2013年11月26日
 */
public class TracesElement {
    
    @NotEmpty
    @Length(max=32)
    private String logisticProviderID;
    
    @NotEmpty
    @Length(max=512)
    private String mailNos;
    
    @Length(max=512)
    private String txLogisticID; 

    @NotNull
    @Valid
    private List<Trace> traces;

    public String getLogisticProviderID() {
        return logisticProviderID;
    }

    public void setLogisticProviderID(String logisticProviderID) {
        this.logisticProviderID = logisticProviderID;
    }

    public String getMailNos() {
        return mailNos;
    }

    public void setMailNos(String mailNos) {
        this.mailNos = mailNos;
    }

    public String getTxLogisticID() {
        return txLogisticID;
    }

    public void setTxLogisticID(String txLogisticID) {
        this.txLogisticID = txLogisticID;
    }
    
    @XmlElementWrapper(name="traces")
    @XmlElement(name="trace")
    public List<Trace> getTraces() {
        return traces;
    }

    public void setTraces(List<Trace> traces) {
        this.traces = traces;
    }
    
    public void addTrace(Trace trace) {
        if (traces == null) {
            traces = new ArrayList<Trace>();
        }
        traces.add(trace);
    }

    @Override
    public String toString() {
        StringBuffer buf = new StringBuffer();
        if (traces != null) {
            for (Trace trace : traces) {
                buf.append(trace).append("; ");
            }
            if (buf.length() >= 2) {
                buf.setLength(buf.length() - 2);
            }
        }
        return "TracesElement [logisticProviderID=" + logisticProviderID + ", mailNos=" + mailNos + ", txLogisticID="
                + txLogisticID + ", traces=" + buf + "]";
    }
}
